﻿  using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBModel;
using DBModel.DAL;

namespace CV_Projekt
{
    public partial class FormAddHeadHunter : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var user = Session["User"] as SuperAdmin;

            if (user == null)
            {
                Response.Redirect("Default.aspx");
            }
        }

        protected void IsUserNameAvailable_ServerValidate(object sender, ServerValidateEventArgs e)
        {
            e.IsValid = UserDB.IsUserNameAvailable(e.Value);
        }

        protected void ButtonCreateAccount_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                HeadHunter headHunter = new HeadHunter
                {
                    UserName = TextBoxUserName.Text.Trim(),
                    Password = TextBoxPassword.Text.Trim(),
                    HeadHunterName = TextBoxHeadHunterName.Text.Trim(),
                    Street = TextBoxAddress.Text.Trim(),
                    PostalCode = TextBoxPostalCode.Text.Trim(),
                    City = TextBoxCity.Text.Trim(),
                    Country = TextBoxCountry.Text.Trim(),
                    Email = TextBoxEmail.Text.Trim(),
                    Phone = TextBoxPhone.Text.Trim()
                };
                int identity = HeadHunterDB.InsertNewHeadHunter(headHunter);
                LabelHeadHunterAdded.Text = string.Format("Ny Headhunter har lagts till.");
                ResetUserInfoTextBoxes();
            }
        }

        private void ResetUserInfoTextBoxes()
        {
            TextBoxUserName.Text = "";
            TextBoxPassword.Text = "";
            TextBoxHeadHunterName.Text = "";
            TextBoxAddress.Text = "";
            TextBoxPostalCode.Text = "";
            TextBoxCity.Text = "";
            TextBoxCountry.Text = "";
            TextBoxEmail.Text = "";
            TextBoxPhone.Text = "";
        }
    }
}